let Fly = require('../lib/fly-wx')
var fly=new Fly(); //创建fly实例
let {KEY,ID,BASE} = require('../config/index')
//添加拦截器
fly.interceptors.request.use((config,promise)=>{
    //给所有请求添加自定义header
    config.headers["X-Tag"]="flyio";
    return config;
})
//配置请求基地址
fly.config.baseURL=BASE
fly.config.headers= {
    "X-LC-Id": ID,
    "X-LC-Key": KEY,
    "Content-Type": "application/json"
}
let statusList = {
    '201':'操作成功',
    '200':'操作成功'
}
//响应拦截器
fly.interceptors.response.use(
    (response) => {
        //只将请求结果的data字段返回
        console.log('响应拦截',response);
        let {status} = response
        wx.showToast({
          title: statusList[status],
          icon:'none'
        })
        // wx.showToast({
        //   title: '加载成功',
        //   icon:'none'
        // })
        // return response.data
    },
    (err) => {
        //发生网络错误后会走到这里
        //return Promise.resolve("ssss")
    }
)

module.exports = fly